<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    {include file='base/common_header'}
    <style>
        .layui-table td, .layui-table th { min-width: auto; }
    </style>
</head>

<body>
<div class="x-nav">
            <span class="layui-breadcrumb">
                <a href="/admin">首页</a>
                <a href="/admin/config">系统配置</a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <form class="layui-form topic-form layui-col-space10">
                    {volist name='list' id='v'}
                    {if condition="$v.type eq 1"}
                    <div class="layui-form-item">
                        <label for="username" class="layui-form-label" style="width: 150px;">
                            {$v.config_name}</label>
                        <div class="layui-input-inline">
                            <input type="text" id="{$v.config_key}" name="config_value[]" value="{$v.config_value}" required="" lay-verify="required" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-form-mid layui-word-aux">{$v.remark}</div>
                        <input type="hidden" name="id[]" value="{$v.id}">
                        <input type="hidden" name="config_name[]" value="{$v.config_name}">
                        <input type="hidden" name="config_key[]" value="{$v.config_key}">
                    </div>
                    {/if}
                    {if condition="$v.type eq 2"}
                    <div class="layui-form-item">
                        <label for="desc" class="layui-form-label" style="width: 150px;">
                            <span class="x-red">*</span>{$v.config_name}</label>
                        <div class="layui-input-block">
                            <button type="button" class="layui-btn" id="{$v.config_key}">
                                <i class="layui-icon">&#xe67c;</i>上传图片
                            </button>
                            <div class="banner-show" style="width: 200px;margin-top: 5px;margin-left: 70px;"><img src="{$v.config_value}" style="width: auto;max-width: 100%;max-height: 100%"></div>
                            <input type="hidden" name="config_value[]" value="{$v.config_value}" class="banner_img">
                            <input type="hidden" name="id[]" value="{$v.id}">
                            <input type="hidden" name="config_name[]" value="{$v.config_name}">
                            <input type="hidden" name="config_key[]" value="{$v.config_key}">
                        </div>
                    </div>
                    <script type="text/javascript">
                        /**
                         * 图片上传
                         * */
                        layui.use('upload', function(){
                            var upload = layui.upload;

                            //执行实例
                            upload.render({
                                elem: "#{$v.config_key}" //绑定元素
                                ,url: '/api/fileUpload' //上传接口
                                ,size: 512
                                ,data:{useOrigin:1}
                                ,done: function(res){
                                    //上传完毕回调
                                    if(res.code == 1){
                                        $("#{$v.config_key}").parents('.layui-input-block').find('.banner-show').find('img').attr('src',res.photo)
                                        $("#{$v.config_key}").parents('.layui-input-block').find('.banner_img').val(res.photo)
                                    }
                                }
                                ,error: function(){
                                    //请求异常回调
                                    layer.msg('上传失败')
                                }
                            });
                        });
                    </script>
                    {/if}
                    {if condition="$v.type eq 3"}
                    <div class="layui-form-item">
                        <label for="username" class="layui-form-label" style="width: 150px;">
                            {$v.config_name}</label>
                        <div class="layui-input-inline">
                            <textarea name="config_value[]"  class="layui-textarea">{$v.config_value}</textarea>
                        </div>
                        <input type="hidden" name="id[]" value="{$v.id}">
                        <input type="hidden" name="config_name[]" value="{$v.config_name}">
                        <input type="hidden" name="config_key[]" value="{$v.config_key}">
                    </div>
                    {/if}
                    {/volist}
                    <div class="layui-form-item">
                        <label for="L_repass" class="layui-form-label"></label>
                        <button class="layui-btn" lay-filter="add" lay-submit="">修改</button></div>
                </form>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    layui.use(['form', 'layer'],
        function() {
            $ = layui.jquery;
            var form = layui.form,
                layer = layui.layer;
            //监听提交
            form.on('submit(add)',
                function(data) {
                    $.post("/admin/config/save",$('.topic-form').serialize(),function (res) {
                        if(res.error_code != 0){
                            layer.msg(res.msg,{icon:5});
                        }else{
                            //发异步，把数据提交给php
                            layer.msg("修改成功", {
                                    icon: 6
                                },
                                function() {
                                    window.parent.location.reload();
                                });
                        }
                    },'json')
                    return false;
                });
        })
</script>

</html>